package com.xinyou.u8c.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author: pxm
 * @Description: TODO
 * @CreateTime: 2023-02-02  11:40
 * @Version: 1.0
 */
@EnableTransactionManagement
@Configuration
@Slf4j
public class MybatisPlusConfig {

//    @Autowired
//    MybatisPlusInterceptor paginationInnerInterceptor;

//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
//        try {
//
//            MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//            sqlSessionFactoryBean.setDataSource(dataSource);
//            //添加XML目录
//            VFS.addImplClass(SpringBootVFS.class);
//            PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//            sqlSessionFactoryBean.setConfigLocation(resolver.getResource("classpath:mybatis/mybatis-config.xml"));
//            sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:com/pxm/nc65/mapper/*.xml"));
//            sqlSessionFactoryBean.setPlugins(paginationInnerInterceptor);
//            return sqlSessionFactoryBean.getObject();
//        } catch (IOException e) {
//            log.error("mybatis resolver mapper*xml is error", e);
//            return null;
//        } catch (Exception e) {
//            log.error("mybatis sqlSessionFactoryBean create error", e);
//            return null;
//        }
//    }


    /**
     *
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQL_SERVER));
        return interceptor;
    }

    @Bean
    public OracleKeyGenerator oracleKeyGenerator(){
        return new OracleKeyGenerator();
    }
}